package cn.it.shop.lucene;

import java.io.File;
import java.io.IOException;

import javax.annotation.PostConstruct;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.wltea.analyzer.lucene.IKAnalyzer;
/*
 * 此类后面用来加载Lucene相关的配置信息,此类建议使用单例默认
 * */
@Component("configuraction")
public class Configuraction {

	private Directory directory=null;
	
	private Analyzer analyzer=null;
	
	@Value(value="#{public.basePath}" + "#{public.indexPath}")
	private String indexPath;
	
	public void setDirectory(Directory directory) {
		this.directory = directory;
	}

	public void setAnalyzer(Analyzer analyzer) {
		this.analyzer = analyzer;
	}
	public Directory getDirectory() {
		return directory;
	}

	public Analyzer getAnalyzer() {
		return analyzer;
	}
	
	@PostConstruct
	public void init(){
		try {
			analyzer=new IKAnalyzer(true);
			directory=FSDirectory.open(new File(indexPath));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
